package com.itheima.stock.listener;

import com.itheima.stock.pojo.domain.InnerMarketDomain;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 监听股票变化消息
 */
@Component
@Slf4j
public class MqListener {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *
     * @param infos
     * @throws Exception
     */
    @RabbitListener(queues = "innerMarketQueue")
    public void acceptInnerMarketInfo(List<InnerMarketDomain> infos)throws Exception{
        log.info("接收消息：{}",infos);
        //热点数据缓存在redis中
        redisTemplate.delete("innerMarketInfos");
        redisTemplate.opsForList().leftPushAll("innerMarketInfos",infos);
    }

}